import {
  Launch
} from 'launch-model.js';
var api = new Launch();
var Function = require("../../../../utils/function.js");
let App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    state: 0,
    type: 0
  },

  //路由跳转

  bindScreen(e) {
    let url = Function.getDataSet(e, 'url');
    Function.linkTo(url);
  },

  linkTo(e) {
    let state = Function.getDataSet(e, 'state');
    let id = Function.getDataSet(e, 'id');
    console.log(state)
    switch (state) {
      case 1:
        Function.linkTo('/pages/work/MyLaunch/vacation/vacation?id=' + id)
        break;

      case 2:
        Function.linkTo('/pages/work/MyLaunch/travel/travel?id=' + id)
        break;

      case 3:
        Function.linkTo('/pages/work/MyLaunch/repair/repair?id=' + id)
        break;
    }
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _this = this;
    _this.setData({
      isLogin: App.checkIsLogin()
    });
    if (_this.data.isLogin === false) {
      wx.navigateTo({
        url: '/pages/login/login',
      })
    }
  },

  //获取列表
  bindList() {
    let date = '';
    api.getSign({ date: date, is_log: 1 }, (res) => {
      if (res.code == 0) {
        App.showError(res.msg, function () {
          wx.navigateBack();
        });
      }else{
        api.getList({
          work_status: this.data.state,
          work_type: this.data.type
        }, (res) => {
          if (res.code == 0) {
            App.showError(res.msg, function () {
              wx.navigateBack();
            });
          }
          this.setData({ list: res.data })
        })
      }
    })    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.bindList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})